﻿//-----------------------------------------------------------------------
// <copyright file="CharacterTest.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using System;
using GateShift.Common.Repository;
using GateShift.Common.Repository.Interfaces.DataInterfaces;
using GateShift.Services.GameData.Entities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#endregion

namespace GateShift.Testing.Services.GameData.Entities
{
    /// <summary>
    /// Summary description for CharacterTest
    /// </summary>
    [TestClass]
    public class CharacterTest
    {
        /// <summary>
        /// Gets or sets the test context which provides
        /// information about and functionality for the current test run.
        /// </summary>
        public TestContext TestContext { get; set; }

        #region CharacterName Validation

        [TestMethod]
        [ExpectedException(typeof(NullReferenceException))]
        public void CharacterName_Null()
        {
            new Character { CharacterName = null };
        }

        [TestMethod]
        [ExpectedException(typeof(IndexOutOfRangeException))]
        public void CharacterName_TooLong()
        {
            new Character { CharacterName = string.Empty.PadRight(21, 'A') };
        }

        [TestMethod]
        public void CharacterName_Success()
        {
            ICharacterData data = new Character { CharacterName = "TestName" };
            Assert.AreEqual("TestName", data.CharacterName, "Mismatched Data");
        }

        [TestMethod]
        public void CharacterName_Default()
        {
            ICharacterData data = new Character();
            Assert.AreEqual(null, data.CharacterName, "Mismatched Data");
        }

        #endregion

        #region Money Validation

        [TestMethod]
        [ExpectedException(typeof(IndexOutOfRangeException))]
        public void Money_UnderZero()
        {
            new Character { Money = Int64.MinValue };
        }

        [TestMethod]
        public void Money_Success()
        {
            ICharacterData data = new Character { Money = 10 };
            Assert.AreEqual(10, data.Money, "Mismatched Data");
        }

        [TestMethod]
        public void Money_Default()
        {
            ICharacterData data = new Character();
            Assert.AreEqual(0, data.Money, "Mismatched Data");
        }

        #endregion

        #region RaceID Reference

        [TestMethod]
        [ExpectedException(typeof(InvalidCastException))]
        public void RaceID_WrongIdentity()
        {
            new Character { RaceID = new Identity(Guid.Empty) };
        }

        [TestMethod]
        public void RaceID_Success()
        {
            ICharacterData data = new Character { RaceID = new Identity((short)123) };
            Assert.AreEqual((short)123, (short)data.RaceID.Value, "Mismatched Data");
        }

        [TestMethod]
        public void RaceID_Default()
        {
            ICharacterData data = new Character();
            Assert.AreEqual(null, data.RaceID, "Mismatched Data");
        }

        #endregion

        #region AccountID Reference

        [TestMethod]
        [ExpectedException(typeof(InvalidCastException))]
        public void AccountID_WrongIdentity()
        {
            new Character { AccountID = new Identity(123) };
        }

        [TestMethod]
        public void AccountID_Success()
        {
            ICharacterData data = new Character { AccountID = new Identity(Guid.Empty) };
            Assert.AreEqual(Guid.Empty, (Guid)data.AccountID.Value, "Mismatched Data");
        }

        [TestMethod]
        public void AccountID_Default()
        {
            ICharacterData data = new Character();
            Assert.AreEqual(null, data.AccountID, "Mismatched Data");
        }

        #endregion
    }
}